# -*- coding: utf-8 -*-
# created on 2017/01/16

from __future__ import division
from sympy import sympify
from mathsolver.functions.hanshu.zhouqi import has_f


def duicheng_fangchenggen(left1, right1, right2, n):
    """hs022.对称性求函数方程根的和"""
    x, fx = sympify('x'), sympify('f(x)')

    if right1 == fx:
        # 类型一
        inner_f = left1.args[0]
    else:
        # 类型二
        b = right1 / 2
        f2aminusx = left1 - fx
        assert not right1.has(x) and has_f(f2aminusx) and right2 == b, '未知等式类型'
        inner_f = f2aminusx.args[0]

    a = (inner_f + x) / 2
    assert not a.has(x), '未知等式类型'

    return n * a


if __name__ == '__main__':
    pass
